home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / mhs_c.arc / OUTPOST.ARC / PARSE.C < prev   
C/C++ Source or Header  |  1988-06-27  |  3KB  |  130 lines

  1. /* ******************************** PARSE.C ******************************* */
  2. #include "cctypes.h"
  3.  
  4. #define LINE_LEN_MAX 81
  5. #define FIRST_WORD_SIZE 37
  6. char currentLine[LINE_LEN_MAX];
  7.  
  8. extern int InFile;
  9. extern int comType;
  10. extern char messageBuffer[];
  11. extern int lineNumber;
  12. extern XRB XRBRec[];
  13.  
  14. void UpperCase();
  15. void AddCurrentLineToMessageBuffer();
  16. int GetNextLine();
  17. void GetFirstWord();
  18.  
  19. int Parse()
  20. {
  21.     int returnCode = NO_ERROR, ccode, bytes = 0, i;
  22.     char firstWord[FIRST_WORD_SIZE], *p;
  23.  
  24.     for ( i = 0; i < 23; i++ ) {
  25.         bytes = GetNextLine();
  26.         bytes = 0;
  27.         while ( currentLine[bytes] != '=' ) bytes++;
  28.         bytes +=2;
  29.         sprintf(XRBRec[i].t, "%s", ¤tLine[bytes]);
  30.     }
  31.  
  32.     bytes = 0;
  33.     while ( 1 ) {
  34.         /* get all the info we need from the SMF header portion of the .XRB file */
  35.         bytes = GetNextLine();
  36.         if ( bytes == 0 ) /* EOF */
  37.             goto Out;
  38.         /* else */
  39.         GetFirstWord(firstWord); /* gets the first word of the current line */
  40.         p = stpblk(firstWord);
  41.         strcpy(firstWord, p);
  42.         if ( strcmp(firstWord, "SMF:") == 0 )
  43.             break;
  44.     }
  45.  
  46.     while (1) { /* as long as we're getting bytes... */
  47.         bytes = GetNextLine(); /* uses InFile and currentLine */
  48.         if ( bytes == 0 ) /* EOF */
  49.             break;
  50.         /* else */
  51.  
  52.         GetFirstWord(firstWord); /* gets the first word of the current line */
  53.  
  54.         ccode = GetCommandType(firstWord);
  55.         if ( ccode != -1 )
  56.             CreateXRBLine(ccode); /* ccode is the switch table index */
  57.         else 
  58.             AddCurrentLineToMessageBuffer();
  59.  
  60.     } /* end while */
  61. Out:
  62.     return(returnCode);
  63. }
  64.  
  65. void AddCurrentLineToMessageBuffer()
  66. {
  67.     char temp[135];
  68.  
  69.     sprintf(temp, "%s\15\12", currentLine);
  70.     strcat(messageBuffer, temp);
  71. }
  72.  
  73. int GetNextLine()
  74. {
  75.     int bytesRead = 0, temp;
  76.     char ch[1];
  77.  
  78.     ch[0] = ' ';
  79.     currentLine[0] = '\0';
  80.     while (ch[0] != 13) {
  81.         temp = read(InFile, ch, 1);
  82.         if ( temp == 0 )
  83.             break;
  84.         currentLine[bytesRead++] = ch[0];
  85.     }
  86.     if ( temp )
  87.         temp = read(InFile, ch, 1); /* ch should be 10 here */
  88.     currentLine[bytesRead-1] = '\0'; /* null terminate where we got the 13 */
  89.     if ( bytesRead )
  90.         lineNumber++;
  91.     return(bytesRead);
  92. }
  93.  
  94. void GetFirstWord(firstWord)
  95. char *firstWord;
  96. {
  97.     firstWord[0] = '\0';
  98.  
  99.     stptok(currentLine, firstWord, FIRST_WORD_SIZE, " ");
  100. }
  101.              
  102. void UpperCase(s)
  103. char *s;
  104. {
  105.     int i = 0;
  106.  
  107.     while ( s[i] != '\0' ) {
  108.         s[i] = islower(s[i]) ? toupper(s[i]) : s[i];
  109.         i++;
  110.     }
  111. }
  112.  
  113. int GetCommandType(command)
  114. char *command;
  115. {
  116.     int i;
  117.  
  118.     if ( strlen(command) ) {
  119.         for ( i = 0; CommandTypes[i]; i++ ) {
  120.             if ( strcmp(command, CommandTypes[i]) == 0 ) {
  121.                 comType = i;
  122.                 return(i);
  123.             }
  124.         }
  125.     }
  126.     return(BADCOMMAND);
  127. }
  128.  
  129.  
  130.